"""
 @Time    : 2022/9/13 15:33
 @Author  : Dylan
 @FileName: ppt2pic.py
 @Software: PyCharm
 @Cnblogs ：https://blog.csdn.net/Clownlaughatyou
 """
import comtypes.client
import os
from Wedding import settings


# file_path = "C:\\Users\\14472\\Desktop\\万达嘉华酒店.pptx"
# output_file_path = "E:\\PycharmProjects\\Wedding\\App\\static\\media\\hotelRes\\万达豪华酒店.pdf"


def convert_ppt(file_name):
    hotel_folder = settings.MEDIA_ROOT + '/hotelRes/'
    input_file_path = os.path.join(hotel_folder, file_name)
    output_file_name = file_name[:-4] + "pdf"
    output_file_path = os.path.join(hotel_folder, output_file_name)
    input_file_path = input_file_path.replace('/', '\\')
    output_file_path = output_file_path.replace('/', '\\')
    powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
    powerpoint.Visible = 1
    slides = powerpoint.Presentations.Open(input_file_path)
    slides.SaveAs(output_file_path, 32)
    slides.Close()
    powerpoint.Quit()


if __name__ == "__main__":
    pass
    # convert_ppt("text.pptx")
